//
//  HalfYearController.m
//  PosApp
//
//  Created by 刘萍 on 2018/9/11.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "HalfYearController.h"

#import "HalfYearViewCell.h"

@interface HalfYearController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *NewsBackView;
@property (weak, nonatomic) IBOutlet UILabel *TimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *AllPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel01;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel02;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel03;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel04;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel05;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel06;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel07;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel08;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel09;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel01;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH01;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice01;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel02;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH02;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice02;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel03;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH03;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice03;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel04;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH04;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice04;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel05;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH05;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice05;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel06;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH06;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice06;

@property (weak, nonatomic) IBOutlet UILabel *TypeLabel07;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TypeViewH07;
@property (weak, nonatomic) IBOutlet UILabel *TypePrice07;


@property (weak, nonatomic) IBOutlet UITableView *NewsTable;
@property (strong, nonatomic) NSMutableArray * HeadDataArr;

@end

@implementation HalfYearController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"半年明细";
    UIButton * leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [leftBtn setImage:[UIImage imageNamed:@"MainBackImage_W"] forState:UIControlStateNormal];
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(5,0,5,20);
    [leftBtn addTarget:self action:@selector(ClickLeftBarButtonItem) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,KScreenW,350);
    gl.startPoint = CGPointMake(0, 0);
    gl.endPoint = CGPointMake(1, 1);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:255/255.0 green:109/255.0 blue:1/255.0 alpha:1].CGColor,(__bridge id)[UIColor colorWithRed:251/255.0 green:41/255.0 blue:67/255.0 alpha:1].CGColor];
    gl.locations = @[@(0.0),@(1.0f)];
    [self.NewsBackView.layer addSublayer:gl];
    self.NewsTable.delegate = self;
    self.NewsTable.dataSource = self;
    self.NewsTable.rowHeight = 70;
    self.NewsTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.NewsTable registerNib:[UINib nibWithNibName:@"HalfYearViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    
    CGAffineTransform endAngle = CGAffineTransformMakeRotation(10 * (M_PI / 180.0f));
    self.TypeLabel01.transform = endAngle;
    self.TypeLabel02.transform = endAngle;
    self.TypeLabel03.transform = endAngle;
    self.TypeLabel04.transform = endAngle;
    self.TypeLabel05.transform = endAngle;
    self.TypeLabel06.transform = endAngle;
    self.TypeLabel07.transform = endAngle;
    
    [self UpLoadDataOfHalfYearController];

}

- (void)UpLoadDataOfHalfYearController{
    
    NSArray * DataArr = @[@12000,@23000,@32000,@9000,@50000,@80000,@65000];
    for (int i = 0; i < DataArr.count; i ++) {
        [self.HeadDataArr addObject:DataArr[i]];
    }
    
    [self SetHeadView];
}



- (void)SetHeadView{
    
    CGFloat maxValue = [[self.HeadDataArr valueForKeyPath:@"@max.floatValue"] floatValue];
    CGFloat minValue = [[self.HeadDataArr valueForKeyPath:@"@min.floatValue"] floatValue];
    NSLog(@"最大值%.2f  最小值%.2f",maxValue,minValue);
    
    for (int i = 0 ; i < self.HeadDataArr.count; i ++) {
        CGFloat h = [self.HeadDataArr[i] floatValue]/10000*17;
        switch (i) {
            case 0:
            {
                    self.TypePrice01.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                    self.TypeViewH01.constant = h;
            }
                break;
            case 1:
            {
                self.TypePrice02.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH02.constant = h;
            }
                break;
            case 2:
            {
                self.TypePrice03.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH03.constant = h;
            }
                break;
            case 3:
            {
                self.TypePrice04.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH04.constant = h;
            }
                break;
            case 4:
            {
                self.TypePrice05.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH05.constant = h;
            }
                break;
            case 5:
            {
                self.TypePrice06.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH06.constant = h;
            }
                break;
            case 6:
            {
                self.TypePrice07.text = [NSString stringWithFormat:@"%@",self.HeadDataArr[i]];
                self.TypeViewH07.constant = h;
            }
                break;
                
            default:
                break;
        }
        
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HalfYearViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[HalfYearViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    return cell;
}

- (void)ClickLeftBarButtonItem{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSMutableArray *)HeadDataArr{
    if (!_HeadDataArr) {
        _HeadDataArr = [NSMutableArray array];
    }
    return _HeadDataArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
